package com.atguigu.controller;

import com.atguigu.entity.Article;
import com.atguigu.service.ArticleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("users/list")
    public List<Article> queryArticleList(@RequestParam Integer userId){
        LambdaQueryWrapper<Article> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Article::getUserId,userId);
        List<Article> articlesList = articleService.list(lambdaQueryWrapper);
        return articlesList;
    }

    @GetMapping("/{articleId}")
    public Article getArticleById(@PathVariable Integer articleId){
        Article article = articleService.getArticleUserAndCommentById(articleId);
        return article;
    }

}
